Add "extended" file metadata to API
[lhc/web/wiklou.git] / includes / filerepo / file / ForeignAPIFile.php
old mode 100644 (file)
new mode 100755 (executable)
index 61d321e..a1a6f26
@@ -86,7 +86,7 @@ class ForeignAPIFile extends File {
         * @return string
         */
        static function getProps() {
-               return 'timestamp|user|comment|url|size|sha1|metadata|mime';
+               return 'timestamp|user|comment|url|size|sha1|metadata|mime|mediatype';
        }
 
        // Dummy functions...
@@ -119,12 +119,25 @@ class ForeignAPIFile extends File {
                // Note, the this->canRender() check above implies
                // that we have a handler, and it can do makeParamString.
                $otherParams = $this->handler->makeParamString( $params );
+               $width = isset( $params['width'] ) ? $params['width'] : -1;
+               $height = isset( $params['height'] ) ? $params['height'] : -1;
 
                $thumbUrl = $this->repo->getThumbUrlFromCache(
                        $this->getName(),
-                       isset( $params['width'] ) ? $params['width'] : -1,
-                       isset( $params['height'] ) ? $params['height'] : -1,
-                       $otherParams );
+                       $width,
+                       $height,
+                       $otherParams
+               );
+               if ( $thumbUrl === false ) {
+                       global $wgLang;
+                       return $this->repo->getThumbError(
+                               $this->getName(),
+                               $width,
+                               $height,
+                               $otherParams,
+                               $wgLang->getCode()
+                       );
+               }
                return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );
        }
 
@@ -156,6 +169,16 @@ class ForeignAPIFile extends File {
                return null;
        }
 
+       /**
+        * @return array|null extended metadata (see imageinfo API for format) or null on error
+        */
+       public function getExtendedMetadata() {
+               if ( isset( $this->mInfo['extmetadata'] ) ) {
+                       return $this->mInfo['extmetadata'];
+               }
+               return null;
+       }
+
        /**
         * @param $metadata array
         * @return array
@@ -232,10 +255,12 @@ class ForeignAPIFile extends File {
        }
 
        /**
-        * @todo FIXME: May guess wrong on file types that can be eg audio or video
         * @return int|string
         */
        function getMediaType() {
+               if ( isset( $this->mInfo['mediatype'] ) ) {
+                       return $this->mInfo['mediatype'];
+               }
                $magic = MimeMagic::singleton();
                return $magic->getMediaType( null, $this->getMimeType() );
        }